package com.jy.adscm.operation.mscyb.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.mscyb.bean.JqcsMachineTest;
import com.jy.adscm.operation.mscyb.bean.JqzzMachine;
import com.jy.adscm.operation.mscyb.bean.QueryJqcsMachineTest;
import com.jy.adscm.operation.mscyb.service.JqcsMachineTestService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-06-13
 */
@RestController
@RequestMapping("/adscm/operation/jqcs/jqcsMachineTest")
public class JqcsMachineTestController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    JqcsMachineTestService jqcsMachineTestService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody JqcsMachineTest jqcsMachineTest, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        jqcsMachineTest.setTaskreleaseperson(token.getUser().getId().toString());
        jqcsMachineTest.setTaskreleaseaddtime(new Date());
        jqcsMachineTest.setTaskfinishstate(0);
        jqcsMachineTest.setTaskstate(0);
        jqcsMachineTest.setIstaskstart("0");
        jqcsMachineTest.setIstaskbegin("0");
        jqcsMachineTest.setIstaskend("0");
        jqcsMachineTest.setIsreviewtask("0");
        jqcsMachineTest.setReviewresult("-1");
        boolean insert = jqcsMachineTestService.insertJqcsMachineTest(jqcsMachineTest);
        return new SimpleCoreResponse("200","新增成功",insert);
    }

    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id)throws AdscmSystemException {
        boolean result = jqcsMachineTestService.deleteById(id);
        return new SimpleCoreResponse("200","删除成功",result);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody JqcsMachineTest jqcsMachineTest, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Boolean result = jqcsMachineTestService.updateJqcsMachineTest(jqcsMachineTest,token);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
    @RequestMapping("selectJqcsMachineTest")
    public  SimpleCoreResponse  selectJqcsMachineTest(@RequestBody QueryJqcsMachineTest queryJqcsMachineTest) throws  AdscmSystemException{
        Page<JqcsMachineTest> page =new Page<>(queryJqcsMachineTest.getCurrentPage(),queryJqcsMachineTest.getPageSize());
        page = jqcsMachineTestService.selectJqcsMachineTest(page,queryJqcsMachineTest);
        return  new SimpleCoreResponse("200","查询成功",page);
    }

    @RequestMapping("selectTaskPerformPerson")
    public  SimpleCoreResponse  selectTaskPerformPerson() throws  AdscmSystemException{
        List<JyUser> users = jqcsMachineTestService.selectTaskPerformPerson();
        return  new SimpleCoreResponse("200","查询成功",users);
    }

}

